package com.dzl.admin;

import com.dzl.base.controller.BaseController;
import com.dzl.enterprise.service.WelfareEnterpriseApiService;
import com.dzl.util.EmptyUtils;
import com.dzl.util.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 第三方API获取token控制层
 * @author liuguanjun
 * @date 2021-11-24 15:52:29
 */
@Slf4j
@RestController
@RequestMapping("")
public class TokenController extends BaseController {

    @Autowired
    private WelfareEnterpriseApiService service;

    /**
     * api接口获取token，第三方接口调用
     * @param appId 商户id
     * @param appSecret 密钥
     * @author liuguanjun
     * @date 2021-11-24 15:44:30
     **/
    @GetMapping("/getToken")
    public JsonResult<String> getWelfareEnterpriseApiToken(String appId, String appSecret) {
        if(EmptyUtils.isEmpty(appId)){
            return JsonResult.failWithMsg("appId不能传空");
        }
        if(EmptyUtils.isEmpty(appSecret)){
            return JsonResult.failWithMsg("appSecret不能传空");
        }
        String token = service.getWelfareEnterpriseApiToken(appId,appSecret);
        return JsonResult.success(token);
    }

}
